package io.gitee.pkmer.base;

import java.nio.charset.StandardCharsets;
import java.util.Base64;

import static okhttp3.Credentials.basic;

/**
 * @author 胖卡
 * @version 1.0.0
 * @date 2024/8/13
 */
public class Base64Main {
    public static void main(String[] args) {
        String username = "pkmer";
        String password = "123456";
        String compose = username + ":" + password;

        String jdkBase64 = Base64.getEncoder().encodeToString(compose.getBytes(StandardCharsets.UTF_8));

        // echo "pkmer:123456" | base64
        // cGttZXI6MTIzNDU2Cg==
        // 如果没有 -n 那么编码的时候会添加换行符号。\n
        // echo -n "pkmer:123456" | base64
        String cmdUbuntuBase64 = "cGttZXI6MTIzNDU2";

        String basicOkHttp = basic(username, password);

        System.out.println(jdkBase64);
        System.out.println(cmdUbuntuBase64);
        System.out.println(basicOkHttp);

    }
}
